{% extends "base.html" %}

{% block title %}{% if is_edit %}编辑成绩{% else %}添加成绩{% endif %}{% endblock %}

{% block content %}
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h3 class="card-title mb-0">{% if is_edit %}编辑成绩{% else %}添加成绩{% endif %}</h3>
                </div>
                <div class="card-body">
                    <form method="POST" action="{{ url_for('edit_score', id=score.id) if is_edit else url_for('add_score') }}">
                        {{ form.hidden_tag() }}
                        
                        <!-- 学生 -->
                        <div class="form-group">
                            {{ form.student_id.label(class="form-label") }}
                            {% if form.student_id.errors %}
                                {{ form.student_id(class="form-select is-invalid") }}
                                <div class="invalid-feedback">
                                    {% for error in form.student_id.errors %}
                                        <span>{{ error }}</span>
                                    {% endfor %}
                                </div>
                            {% else %}
                                {{ form.student_id(class="form-select") }}
                            {% endif %}
                        </div>
                        
                        <!-- 课程 -->
                        <div class="form-group">
                            {{ form.course_id.label(class="form-label") }}
                            {% if form.course_id.errors %}
                                {{ form.course_id(class="form-select is-invalid") }}
                                <div class="invalid-feedback">
                                    {% for error in form.course_id.errors %}
                                        <span>{{ error }}</span>
                                    {% endfor %}
                                </div>
                            {% else %}
                                {{ form.course_id(class="form-select") }}
                            {% endif %}
                        </div>
                        
                        <!-- 成绩 -->
                        <div class="form-group">
                            {{ form.score.label(class="form-label") }}
                            {% if form.score.errors %}
                                {{ form.score(class="form-control is-invalid") }}
                                <div class="invalid-feedback">
                                    {% for error in form.score.errors %}
                                        <span>{{ error }}</span>
                                    {% endfor %}
                                </div>
                            {% else %}
                                {{ form.score(class="form-control", placeholder="请输入成绩") }}
                            {% endif %}
                        </div>
                        
                        <!-- 备注 -->
                        <div class="form-group">
                            {{ form.remark.label(class="form-label") }}
                            {% if form.remark.errors %}
                                {{ form.remark(class="form-control is-invalid", rows=3) }}
                                <div class="invalid-feedback">
                                    {% for error in form.remark.errors %}
                                        <span>{{ error }}</span>
                                    {% endfor %}
                                </div>
                            {% else %}
                                {{ form.remark(class="form-control", rows=3, placeholder="请输入备注信息（可选）") }}
                            {% endif %}
                        </div>
                        
                        <!-- 提交按钮 -->
                        <div class="form-group text-center mt-4">
                            <button type="submit" class="btn btn-primary btn-lg">
                                <i class="fas fa-save me-2"></i>{% if is_edit %}更新成绩{% else %}添加成绩{% endif %}
                            </button>
                            <a href="{{ url_for('scores') }}" class="btn btn-secondary btn-lg">
                                <i class="fas fa-times me-2"></i>取消
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}